package com.beidouapp.manager.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.beidouapp.common.util.DateUtils;
import com.beidouapp.dao.MonthlySummaryMapper;
import com.beidouapp.domain.pojo.MonthlySummary;
import com.beidouapp.manager.MonthlySummaryManager;

@Repository
public class MonthlySummaryManagerImpl implements MonthlySummaryManager{
	@Autowired
	MonthlySummaryMapper monthlySummaryMapper;

	@Override
	public List<MonthlySummary> getMonthlyDataStatis() {
		return monthlySummaryMapper.getMonthlyDataStatis();
	}

	@Override
	public List<MonthlySummary> get12MonthlyData(Date startDate) {
		long startNoMilTime=startDate.getTime()/1000;
		Map<String, Object> paraMap=new HashMap<String,Object>();
		paraMap.put("startDate", startDate);
		paraMap.put("startTime", startNoMilTime);
		List<String> months=DateUtils.get11Monthly(startDate);
		String currentMon = DateUtils.getMonthFirstDay(new Date(), "YYYY-MM");
		paraMap.put("months", months);
		List<MonthlySummary>	monthlySummarys=monthlySummaryMapper.get12MonthlyData(paraMap);
		Map<String, MonthlySummary> mmapMap= new HashMap<String, MonthlySummary>();
		for(MonthlySummary monthlySummary:monthlySummarys){
			mmapMap.put(monthlySummary.getShortTime(), monthlySummary);
		}
		List<MonthlySummary> monthlySummaries=new ArrayList<MonthlySummary>();
		months.add(currentMon);
		for(String monthly:months){
			if(mmapMap.containsKey(monthly)){
				monthlySummaries.add(mmapMap.get(monthly));
				continue;
			}
			MonthlySummary summary = new MonthlySummary();
			summary.setShortTime(monthly);
			summary.setEngineerAmount(0);
			summary.setProjectAmount(0);
			monthlySummaries.add(summary);
		}
		return monthlySummaries;
	}
	
	public static void main(String[] args) {
		Date startDate=DateUtils.getDateWithStart(new Date());
		long startNoMilTime=startDate.getTime()/1000;
		System.out.println(startNoMilTime);
	}
}